﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Control.Dal;

namespace Control.Bus
{
    public class BusExportBill
    {
        public int ID { get; set; }
        private BusStaff staff;
        public BusStaff Staff
        {
            set { staff = value; }
            get
            {
                if (staff == null)
                    staff = new BusStaff();
                return staff;
            }
        }
        public DateTime Date { get; set; }
        public string BillCode { get; set; }
        
        public string BillName { get; set; }
        


        public static BusExportBill FindByDateAndStaff(DateTime dateTime, BusStaff staff)
        {
            BusExportBill resuilt = new BusExportBill()
            {
                ID = -1,
                staff = staff,
                Date = dateTime
            };
            
            List<BusExportBill> bills = new List<BusExportBill>();
            bills = DalExportBill.GetByStaff(staff);
            foreach (BusExportBill item in bills)
            {
                if (dateTime.ToShortDateString().CompareTo(item.Date.ToShortDateString()) == 0)
                {
                    resuilt = item;
                }
            }
            return resuilt;
        }

        public void Insert()
        {
            ID =  DalExportBill.Insert(this);
        }

        public List<BusExportBillDetail> GetBillDetail()
        {
            return DalExportBillDetail.GetListByBill(this);
        }

        public static BusExportBill GetBillThuongByDateAndStaff(DateTime dateTime, BusStaff Staff)
        {
            BusExportBill resuilt = new BusExportBill()
            {
                ID = -1,
            };
            List<BusExportBill> bills = new List<BusExportBill>();
            bills = DalExportBill.GetByStaff(Staff);
            foreach (BusExportBill item in bills)
            {
                if (dateTime.ToShortDateString().CompareTo(item.Date.ToShortDateString()) == 0 && item.BillCode == null)
                    resuilt = item;
                
            }
            return resuilt;

        }

        public void UpDate()
        {
            DalExportBill.UpDate(this);
        }

        public static List<BusExportBill> GetListByDateAndStaff(DateTime dateTime, BusStaff staff)
        {
            List<BusExportBill> resuilt = new List<BusExportBill>();
            List<BusExportBill> Bills = new List<BusExportBill>();
            Bills = DalExportBill.GetByStaff(staff);
            foreach (BusExportBill item in Bills)
            {
                if (item.Date.ToShortDateString().CompareTo(dateTime.ToShortDateString()) == 0)
                    resuilt.Add(item);
            }
            return resuilt;
        }


    }
}
